package by.grsu.epam.domain.account;

import java.util.GregorianCalendar;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import by.grsu.epam.domain.service.Service;

@Entity
public class Bill {
	private Long id;
	private Service service;
	private GregorianCalendar date;
	private boolean unpaid;
	private Account account;
	
	public Bill(){
		date = new GregorianCalendar();
		unpaid = true;
	}
	
	public Bill(Service service){
		this.service = service;
		date = new GregorianCalendar();
		unpaid = true;
	}		
	
	public void payOnBill(){
		unpaid = false;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@OneToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "service_id")
	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public GregorianCalendar getDate() {
		return date;
	}

	public void setDate(GregorianCalendar date) {
		this.date = date;
	}

	public boolean isUnpaid() {
		return unpaid;
	}

	public void setUnpaid(boolean unpaid) {
		this.unpaid = unpaid;
	}

	@ManyToOne
	@JoinColumn(name = "account_Id")
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}
	
}
